Mobile: Mobile System Interop
Operate current mobile device functions, such as camera.
edger.env()
- Returns: {Promise} Promise object.
The data
object contains the following members:
id
{String} App unique identifier.env
{String} App environment. Including:edgerapp
oredgerpc
.brand
{String} App brand of the mobile phone. Including:apple
,xiaomi
,oppo
,vivo
, etc.platform
{String} App platform. Including:android
orios
.appVersion
{String} App version.osVersion
{String} Operating system version.
Developers can determine whether this function works in the EdgerOS mobile App environment through the following code:
edger.env().then(data => {
if (data.env === 'edgerapp') {
// We work in EdgerOS mobile App environment.
}
}).catch(error => {
console.error(error);
});
Functions
edger.mobile.qrscan()
- Returns: {Promise} Promise object.
Scan the QR code through the mobile camera.
Example
edger.mobile.qrscan().then((data) => {
const { format, text } = data;
console.log('qrscan successful, ', format, text)
}).catch(error => {
// Maybe the user cancelled this scan.
console.log('qrscan failed', error)
});
async / await
async function qrscan() {
try {
await edger.mobile.qrscan();
} catch (error) {
console.error(error);
}
}
edger.mobile.getVolume()
- Returns: {Promise} Promise object.
Get an object of result, the object includes:
volume
{String} Get the volume size of the mobile device in the range 0-100.
Example
edger.mobile.getVolume().then((data) => {
const { volume } = data;
console.log('get volume successful, ', volume)
}).catch(error => {
console.log('get volume failed', err)
});
async / await
async function getVolume() {
try {
const data = await edger.mobile.getVolume();
const { volume } = data;
console.log('get volume successful, ', volume)
} catch (error) {
console.error(error);
}
}
edger.mobile.networkInfo()
Get mobile phone system network information.
- Returns: {Promise<NetworkInfo>} Promise object.
Get an object of result, the object includes:
type
{String} Type of mobile network. Optional values:none
|wifi
|mobile
.ip
{String} Mobile network IP addressssid
{String} The SSID corresponding to the current WI-FI, when the mobile phone network is WI-FI.
Example
edger.mobile.networkInfo().then((info) => {
console.log('get mobile network successful, ', info)
}).catch((error) => {
console.error(error);
});
async / await
async function networkInfo() {
try {
const info = await edger.mobile.networkInfo();
console.log('get mobile network successful, ', info)
} catch (error) {
console.error(error);
}
}
Events
The unified event listener provided by Web-SDK:
const listener = (payload) => {
// Event handling...
}
// add listener
edger.mobile.addEventListener('some-event', listener);
// or
// onAction() is an alias of addEventListener().
edger.mobile.onAction('some-event', listener);
// remove listener
edger.mobile.removeEventListener('some-event', listener);
// remove all listeners
edger.mobile.removeAllListeners();
volumeChange
Triggered when the mobile device volume changes
- Returns: {Object} A
volumeInfo
object.
Get an object of result, the object includes:
volume
{String} Get the volume size of the mobile device in the range 0-100.
Example
const listener = (payload) => {
const { volume } = payload;
console.log("volume change result:", volume);
}
edger.mobile.addEventListener('volumeChange', listener);